package miku.firstgame.entity
{
	import com.saia.starlingPunk.SPEntity;
	import com.saia.starlingPunk.SPMask;

	import miku.firstgame.event.PlayerEvent;

	import starling.animation.DelayedCall;
	import starling.animation.Transitions;
	import starling.animation.Tween;
	import starling.core.Starling;
	import starling.display.Image;
	import starling.textures.Texture;

	public class Bomb extends SPEntity
	{
		[Embed(source = "media/bomb.png")]
		public const ui:Class;
		public var energy:int = 2;

		private var delayCall:DelayedCall;

		public function Bomb()
		{
			super(0, 0, "Bomb");
		}

		override public function added():void
		{
			super.added();
			setupGraphic();

//			var tween:Tween = new Tween(this, 1.0, Transitions.EASE_IN);
//			tween.animate("alpha", 0.0);

			delayCall = Starling.juggler.delayCall(explode, 2.0);
		}

		public function explode():void
		{
			var event:PlayerEvent = new PlayerEvent(PlayerEvent.EXPLODE);
			dispatchEvent(event);

			Starling.juggler.remove(delayCall);
			delayCall = null;
			//removeFromParent(true); 
		}

		private function setupGraphic():void
		{
			var image:Image = new Image(Texture.fromBitmap(new ui()));
			addChild(image);
		}

		override public function removed():void
		{
			removeChildren(0, -1, true);
			super.removed();
		}

		override public function update():void
		{
			super.update();
//			updateMovement();
//			updateInput(); 
//			updateCollision(); 
			var entity:SPEntity = collide("fire", x, y);
			if (entity is FireEntity)
			{
				this.explode();
			}

		}
	}
}
